<%-- 
    Document   : VMHotel
    Created on : 01/06/2010, 20:08:22
    Author     : TIAGO
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import="br.terminalrodoviario.Hotel"%>
<%@page import="java.util.*, java.text.*" %>
<jsp:useBean class="br.terminalrodoviario.Hotel" id="Hotel" scope="page"/>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
        <title>Guia Terminal Rodoviário</title>
        <style type="text/css" rel="stylesheet">
            @import url("add/css/cssAdmin.css");
            @import url("add/css/cod.css");
            @import url("../add/css/rodape.css");
        </style>
        <script type="text/javascript" src="add/js/jquery.js"></script>

        <script type="text/javascript" src="add/js/jquery.innerfade.js"></script>

        <script type="text/javascript" src="add/js/config.js"></script>
        <script type="text/javascript">
            function search(){
                location = "VMHotel.jsp?search="+document.getElementById("txtSearch").value;
            }
            function keyPress(event){
                var keyNum;
                if(window.event){
                    keyNum=event.keyCode;
                }else if(event.which){
                    keyNum=event.which;
                }
                if(event.keyCode == 13){
                    search();
                }
            }
        </script>
    </head>

    <body>

        <div class="geral">
            <table>
                <tr>
                    <td>
                        <div id="cabecalho"></div>
                    </td>
                </tr>
            </table>
            <div style="float:left">
                &nbsp;&nbsp;<b><a href="index.jsp">Início</a> -> <a href="VMHotel.jsp">Hotéis</a></b>
            </div>
            <div align="right" style="font-family:calibri; font-size:13px;"><a href="Company/login.jsp">Área Restrita</a>&nbsp;&nbsp;&nbsp;</div>
            <table>
                <tr>
                    <td>
                        <div>
                            <ul class="menu">
                                <li><a href="index.jsp"><b>início</b></a></li>
                                <li><a href="VMCompany.jsp"><b>empresas</b></a></li>
                                <li><a href="VMBusStation.jsp"><b>terminais rodoviários</b></a></li>
                                <li class="current"><a href="VMHotel.jsp"><b>hotéis</b></a></li>
                                <li><a href="VMNotice.jsp"><b>notícias</b></a></li>
                                <li><a href="VMTravelTip.jsp"><b>dicas de viagem</b></a></li>
                            </ul>
                        </div>
                    </td>
                </tr>
            </table>

            <div id="conteudo" align="center">
                <%
                            String search = request.getParameter("search");
                            Collection<Hotel> lst = new Hotel().select("from Hotel n" + (search != null ? " where n.name like '%" + search + "%'" : "") + " order by n.name asc");
                            if (lst != null && lst.size() != 0 && !lst.isEmpty()) {
                %>

                <table width="765">
                    <tr>
                        <td>
                            <div style="float:left">
                                <table id="subTitulo2">
                                    <tr>
                                        <td id="icone" align="center">
                                            &nbsp;&nbsp;&nbsp;<img src="add/images/icones/hotel.png" alt="Hotéis" title="Hotéis"/>
                                        </td>
                                        <td>
                                            Hotéis
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                        <td>
                            <div style="font-family:calibri;font-style:13px;float:right">
                                <table>
                                    <tr>
                                        <td class="label_bg" style="width:70px;" align ="center">
                                            <b>Pesquisar:</b>
                                        </td>
                                        <td>
                                            <input type="text" onkeypress="keyPress(event);" size="35" id="txtSearch" name="txtSearch" value="<%=search != null ? search : ""%>"/>
                                        </td>
                                        <td>
                                            <img src="add/images/botoes/search.png" name="Buscar" style="cursor:pointer;" value="Buscar" onclick="javascript:search();" alt="Procurar" title="Procurar"/>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                </table>

                <table border="0" width="750" cellspacing="0" cellpadding="0" style="font-family:calibri">
                    <tr class="table_header">
                        <th align="left">Nome</th>
                        <th align="left">Cidade/Estado</th>
                    </tr>
                    <%
                        Object[] hotels = lst.toArray();
                        int total = hotels.length > 15 ? 15 : hotels.length;
                        int i = 0;
                        int inicio = 0;
                        int pagina = 1;
                        if (request.getParameter("page") != null) {
                            pagina = Integer.parseInt(request.getParameter("page"));
                        }
                        if (pagina > 1) {
                            inicio = total * pagina - total;
                        }
                        int fim = total * pagina;
                        if (fim > hotels.length) {
                            fim = hotels.length;
                        }
                        if (hotels.length > 0) {
                            for (int j = inicio; j < fim; j++) {
                                Hotel n = (Hotel) hotels[j];
                    %>
                    <tr class="<%=(i % 2 != 0) ? "table_row_bg" : "table_row"%>">
                        <td align="left" width="500px"><a href="VFHotel.jsp?id=<%=n.getId()%>"><%=n.getName()%></a></td>
                        <td align="left"><%=n.getCity().getFullName()%></td>
                    </tr>
                    <%
                                                            i++;
                                                        }
                                                    }
                    %>
                    <tr>
                        <td colspan="6" align="center">
                            Páginas : <%
                                                            int totalPaginas = hotels.length / (total == 0 ? 1 : total);
                                                            if (hotels.length % (total == 0 ? 1 : total) != 0) {
                                                                totalPaginas++;
                                                            }
                                                            for (int j = 1; j <= totalPaginas; j++) {
                            %>
                            <a href="MHotel.jsp?page=<%=j%>"><%= (j == pagina ? "<b>" : "")%><%=j%><%= (j == pagina ? "</b>" : "")%></a>
                            <%
                                                            }
                            %>
                        </td>
                    </tr>
                </table>
                <%} else {%>
                <h3>Não há nenhum registro.</h3>
                <%}%>
            </div>
            <br/><br/>
            <table id="rodape" style="background-image:url(add/images/rodape.png);">
                <tr>
                </tr>
            </table>
            <table id="btRodape" style="text-decoration: none;" >
                <tr>
                    <td align="center" width="80px">
                        <ul class="btYoutube">
                            <li><a title="Youtube" href="http://www.youtube.com" /></li>
                        </ul>
                    </td >
                    <td align="center" width="80px">
                        <ul class="btOrkut">
                            <li><a title="Orkut" href="http://www.orkut.com" /></li>
                        </ul>
                    </td>
                    <td align="center" width="205px">
                        <ul class="btTwitter">
                            <li><a title="Twitter" href="http://twitter.com" /></li>
                        </ul>
                    </td>
                    <td align="center">
                        <a title="Trabalhe Conosco" class="text" href="Carrer.jsp" >Trabalhe Conosco</a>
                    </td>
                    <td align="center"  width="">
                        <a title="Mapa do Site" class="text" href="SiteMap.jsp">Mapa do Site</a>
                    </td>
                    <td align="center" width="">
                        <a title="Contatos" class="text" href="Contact.jsp">Contatos</a>
                    </td>
                </tr>
            </table>
        </div>
    </body>
</html>

